subroutine r1ai_t2efmi_iefam(r1, t2, iabci,& 
               icore, fact)
!
use mod_ioff
use mod_orbit
use mod_size 
use mod_iop
implicit none
!
real*8, intent(inout) :: fact
real*4, intent(in) :: r1(*)
real*4, intent(in) :: iabci(*)
!
real*4, intent(inout) :: t2(*), icore(*)
!
integer :: i, j, a, b, nsize
integer :: i0, i1, i2, i3
integer, external :: irpdso
real*8, external :: dnrm2
!this is to do r1(ai) = r1(ai) -0.5*t2(ef,mi)*<ef||am>
!
i0 = 1
i1 = i0 + nvvoo*isd
i2 = i1 + nvvvo*isd
!===AA
!<EF||AM>*T2(EF,MI)
!call isymtrso(iabci(ioi5(1)), icore(i1), vrta, vrta, 0, 0, vrta, popa, 1, 1, 1) 
!call iexpso(t2(ioi3(1)), icore(i0), vrta, vrta, 0, 0, popa, popa, 0, 1, 1) 
!call VpqrmVpqrn_to_Vmn(icore(i1), icore(i0), 1, 1, vrta, vrta, 0, &
!                      popa, vrta, popa, r1(ifvo(1)), 1, fact*2.d0)
!nsize = irpdso(1, vrta, popa, 1)
!write(6,*)'norm of aa 1', dnrm2(nsize, r1(ifvo(1)), 1)
!<eF||Am>*T2(eF,mI) = - <Fe|Am>*T2(Fe,Im)
!call isymtrso(iabci(ioi5(2)), icore(i1), vrta, vrta, 1, 0, vrta, popa, 1, 1, 1) 
!call isymtrso(t2(ioi3(2)), icore(i0), vrta, vrta, 1, 0, popa, popa, 1, 1, 1) 
!call VpqrmVpqrn_to_Vmn(icore(i1), icore(i0), 1, 1, vrta, vrta, 1, &
!                      popa, vrta, popa, r1(ifvo(1)), 1, -fact*2.d0)
nsize = irpdso(1, vrta, popa, 1)

call isymtrso(t2(ioi3(2)), icore(i2), vrta, vrta, 1, 1, popa, popa, 1, 0, 1) 
call scalso(nioi32, -1.d0, icore(i2), 1)
call axpyso(nioi32, 2.d0, t2(ioi3(2)), 1, icore(i2), 1)

call isymtrso(iabci(ioi5(2)), icore(i1), vrta, vrta, 1, 0, vrta, popa, 1, 1, 1)
call isymtrso(icore(i2), icore(i0), vrta, vrta, 1, 0, popa, popa, 1, 1, 1)
call VpqrmVpqrn_to_Vmn(icore(i1), icore(i0), 1, 1, vrta, vrta, 1, &
                      popa, vrta, popa, r1(ifvo(1)), 1, -fact*2.d0)

!write(6,*)'norm of aa 2', dnrm2(nsize, r1(ifvo(1)), 1)
return
end
